package com.meihua.shellapp.activity.maker;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.bean.StoreManageBean;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;

/**
 * 作者：lc on 2017/9/27.
 * 邮箱：lc0607live@163.com
 */

public class MakerCenterActivity extends BaseActivity {

    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题

    @Bind(R.id.rl_makerselect)
    RelativeLayout rl_makerselect;//创客查询
    @Bind(R.id.rl_achievementselect)
    RelativeLayout rl_achievementselect;//业绩查询
    @Bind(R.id.rl_policymanage)
    RelativeLayout rl_policymanage;//保单管理
    @Bind(R.id.rl_customermanage)
    RelativeLayout rl_customermanage;//客户管理
    @Bind(R.id.rl_storemanage)
    RelativeLayout rl_storemanage;//门店管理

    @Override
    public int getLayoutId() {
        return R.layout.activity_makercenter;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("创客中心");
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);

        rl_makerselect.setOnClickListener(this);
        rl_achievementselect.setOnClickListener(this);
        rl_policymanage.setOnClickListener(this);
        rl_customermanage.setOnClickListener(this);
        rl_storemanage.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        Intent in = new Intent();
        switch (view.getId()) {
            case R.id.rl_storemanage://门店管理
                checkIsEnter();
                break;
            case R.id.rl_achievementselect://业绩查询
                in.setClass(mContext, AchievementSelectActivity.class);
                startActivity(in);
                break;
            case R.id.rl_policymanage://保单管理
                in.setClass(mContext, PolicyManageActivity.class);
                startActivity(in);
                break;
            case R.id.rl_customermanage://客户管理
                in.setClass(mContext, CustomerManageActivity.class);
                startActivity(in);
                break;
            case R.id.rl_makerselect://创客查询
                in.setClass(mContext, MakerSelectActivity.class);
                startActivity(in);
                break;
        }
    }

    /**
     * 监测是否进入
     */
    private void checkIsEnter() {
        OkGo.<String>post(URL.getUrl().GETSTOREMANAGE)
                .params("m_number", MyApplication.getInstance().getUserId())
                .params("member_level", MyApplication.getInstance().bean.getMember_level())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        StoreManageBean bean = MyApplication.getInstance().getBeanForJson(StoreManageBean.class, response.body());
                        if (bean == null) {
                            return;
                        }
                        String message = "";
                        if (bean.getCode() == 1) {
                            switch (bean.getData()) {
                                case "1":
                                    startActivity(new Intent(MakerCenterActivity.this, StoreManageActivity.class));
                                    break;
                                case "2"://不具备申请资格
                                    message = "对不起，您不具备申请资格";
                                    break;
                                case "3"://审核
                                    message = "正在审核中，请耐心等待...";
                                    break;
                                case "4"://未通过
                                    message = "对不起，您的审核未通过。";
                                    break;
                                case "5"://通过
                                    message = "您的审核已通过!";
                                    break;
                            }
                            ToastUtils.getInstance().showToast(message);
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });

//
    }
}
